﻿@model IEnumerable<Commission.Models.Product>
@using MyResources = Commission.Resources.AppResource

@{
    ViewBag.Title = "Index";
}

@section Sortable {
    @Scripts.Render("~/bundles/sortable")
}

<h3>@MyResources.LabelProductList</h3>

@if (User.IsInRole("Admin")) {
<p>
    @Html.ActionLink(@MyResources.LinkAddNewProduct, "Create")
</p>
}
    
<table class="table hoverTable sortable">
    <tr>
        <th style="width:80px">
            @MyResources.LabelProductNo
        </th>
        <th style="width:210px">
            @MyResources.LabelProductName
        </th>
        <th style="width:120px">
            @MyResources.LabelProductImage
        </th>
        <th class="text-center" style="width:100px">
            @MyResources.LabelKHPrice
        </th>

        <th style="width:90px">
            @MyResources.LabelUnit
        </th>
        <th class="text-center" style="width:100px">
            @MyResources.LabelPPPoint
        </th>
        <th class="text-center">
            @MyResources.LabelNote
        </th>

        @if (User.IsInRole("Admin"))
        {
            <th style="width:172px"></th>
        }
    </tr>

    @foreach (var item in Model)
    {
        <tr>

            <td>
                @Html.DisplayFor(modelItem => item.ProductNo)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.ProductName)
            </td>
            <td>
                @if (item.FileId != null && item.FileId != 0)
                {
                    <img src="@Url.Content(item.FileUrl)" height="100" width="100" alt="Image" />
                }
            </td>
            <td class="text-right">
                @Html.Raw(string.Format("{0:#,0}", item.Price))
            </td>

            <td class="text-center">
                @Html.DisplayFor(modelItem => item.Unit.UnitName)
            </td>
            <td class="text-right">
                @Html.Raw(string.Format("{0:#,0.0}", item.PPPoint))
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Note)
            </td>

            @if (User.IsInRole("Admin"))
            {
                <td>
                    @Html.ActionLink(@MyResources.LinkEdit, "Edit", new { id = item.ProductId }) |
                    @Html.ActionLink(@MyResources.LinkDetail, "Details", new { id = item.ProductId }) |
                    @Html.ActionLink(@MyResources.LinkDelete, "Delete", new { id = item.ProductId })
                </td>
            }
        </tr>
    }

</table>
